package com.hmall.order.web;

import com.hmall.order.pojo.Order;
import com.hmall.order.pojo.OrderSubmit;
import com.hmall.order.service.IOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("order")
public class OrderController {

   @Autowired
   private IOrderService orderService;

   /**
    * 创建订单
    * @param orderSubmit 客户提交订单自定义接收数据类型
    * @return 订单id
    */
   /*请求 URL: http://localhost:10010/order
   请求方法: POST
   {"num":1,"paymentType":3,"addressId":61,"itemId":100002672307}*/
   @PostMapping
   public Long submit(@RequestBody OrderSubmit orderSubmit){
      log.info("[订单微服务===>提交订单，订单信息：{}]",orderSubmit.toString());
      return orderService.submit(orderSubmit);
   }


   @GetMapping("{id}")
   public Order queryOrderById(@PathVariable("id") Long orderId) {
      return orderService.getById(orderId);
   }
}
